﻿Imports CRM.BusinessLayer
Partial Public Class frmAbout

    Private Sub frmAbout_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles Me.KeyUp
        If e.Key = Key.Escape Then
            Me.Close()
        ElseIf e.Key = Key.C Then
        End If
    End Sub

    Private Sub Window1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
        Try
            GeneralTasks.ChangeTheme(Me)
            GeneralTasks.EnumerateandFill(Me.LogicalChildren)
            Me.Title = "About CRM" & "(" & My.Application.Info.Version.ToString & ")"
            Dim strSQL As String = CommonFuncs.GetDBConnectionString
            Dim str() As String
            If strSQL <> "" Then
                str = Split(strSQL, ";")
            End If
            Me.txtconnection.Text = "Version : " & My.Application.Info.Version.ToString '& "." & My.Application.Info.Version.Minor.ToString & "." & My.Application.Info.Version.Revision.ToString & vbCrLf & My.Application.Info.Version.ToString

            'Dim configurationAppSettings As System.Configuration.AppSettingsReader = New System.Configuration.AppSettingsReader
            'Dim strDatabase As String = CType(configurationAppSettings.GetValue("CompanyInfo", GetType(System.String)), String)
            'GetDBConnectionString = strDatabase
            'txtCompanyInformation.Text = strDatabase
            Dim brndetails As BranchRecord
            Dim intBranchID As Integer
            intBranchID = CommonDataFunctions.GetBranchID(GlobalCRM.CurrentConID)

            brndetails = Branch.GetBranch(intBranchID)
            txtCompanyInformation.Text = brndetails.Branch_Name & vbCrLf & vbCrLf & brndetails.Branch_Address1 & vbCrLf & brndetails.Branch_Address2 & vbCrLf & brndetails.Branch_Address3 & vbCrLf & brndetails.Branch_Address4
            txtCompanyInformation.Text = txtCompanyInformation.Text & vbCrLf & brndetails.Branch_Address5 & vbCrLf & brndetails.Branch_Postcode & vbCrLf & brndetails.Branch_TelNo

        Catch ex As Exception
            txtCompanyInformation.Text = "Company Information unavailable. " & vbCrLf & "Please contact IT"
            CommonFuncs.ErrorHandler(ex, "frmAbout.LinkLabel1_LinkClicked", True)
            Exit Sub
        Finally
            If txtCompanyInformation.Text = String.Empty Then
                txtCompanyInformation.Text = "Company Information unavailable. " & vbCrLf & "Please contact IT"
            End If
        End Try

    End Sub

    Private Sub frmAbout_TextInput(ByVal sender As Object, ByVal e As System.Windows.Input.TextCompositionEventArgs) Handles Me.TextInput
        If e.Text.GetHashCode = -842352715 Then
            Me.Close()
        End If
    End Sub

    Private Sub btnInstall_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
        Dim strVersion As String = CommonDataFunctions.LatestVersionRolledOut.Trim
        Dim strInstallationPath As String
        If strVersion <> My.Application.Info.Version.ToString Then
            If MsgBox("Latest version of CRM v" & strVersion & " is available now. " & vbCrLf & "If you would like to install the latest version, please push the button 'Yes'." & vbCrLf & vbCrLf & "All the other programs remain unaffected.", MsgBoxStyle.YesNo, "Latest Version") = MsgBoxResult.Yes Then
                'frmMDIMain.InstallLatstVersionToolStripMenuItem_Click(sender, e)
                strInstallationPath = CommonDataFunctions.GetBranchInstallationPath()
                If strInstallationPath <> String.Empty Then
                    System.Diagnostics.Process.Start(strInstallationPath)
                    End
                Else
                    CommonFuncs.DisplayMessage("The Branch installation path is not confugured. please contact IT", CommonDialog.CustomDialogIcons.Information, "Installation")
                End If

                'btnExit_Click(sender, e)
            Else
                Exit Sub
            End If
        Else
            CommonFuncs.DisplayMessage("You have got the latest version installed on your machine.", CommonDialog.CustomDialogIcons.Information, "IT")
        End If
    End Sub

    Private Sub btnReport_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnReport.Click
        Dim frmReport As New ReportCriteria()
        frmReport.Show()
        Me.Close()
    End Sub



    Private Sub btnChangeCRMPassword_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnChangeCRMPassword.Click
        Dim frmChangeNTPassword As New frmChangeNTPassword()
        frmChangeNTPassword.ShowDialog()
    End Sub

    Private Sub btnSettings_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSettings.Click
        Dim frmSettings As New frmSettings()
        frmSettings.ShowDialog()
        frmSettings = Nothing
        Me.Close()
    End Sub

    Private Sub btnChangeCRMEmailPassword_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnChangeCRMEmailPassword.Click
        Dim frmChangeEmailPassword As New frmChangeEmailPassword()
        frmChangeEmailPassword.ShowDialog()
    End Sub
End Class
